import axios from "axios";
const requests = axios.create({ 

    baseURL: import.meta.env.VITE_APP_API_BASEURL, 
    timeout: 5000, 
    headers: { 
        "Content-Type": "application/json",
        'Authorization':localStorage.getItem('accessToken'),
    }

})

// 添加响应拦截器
requests.interceptors.response.use(
  response => response,
  error => {
    if (error.response.status === 401) {
      localStorage.removeItem('accessToken');
      window.location.href = '/';
      alert('请先登录');
    }
    return Promise.reject(error);
  }
);

export default requests;